package work.kingcrab.file.server.controller;

import work.kingcrab.file.server.response.SimpleResponse;
import work.kingcrab.file.server.utils.FileUploadUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Yousheng Tao
 * @description tools
 * @since 2020/7/30 15:31
 */
@RequestMapping("/api")
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FileUploadController {
    private final FileUploadUtils fileUploadUtils ;

    /**
     * 批量上传文件
     */
    @PostMapping("/upload")
    public SimpleResponse save(HttpServletRequest request){
        return SimpleResponse.success(fileUploadUtils.save(request)) ;
    }

    /**
     * 批量删除文件
     */
    @PostMapping("/del")
    public SimpleResponse del(@RequestParam(value = "urls") List<String> urls){
        return SimpleResponse.success(fileUploadUtils.del(urls)) ;
    }
}
